/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Security;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;  
import java.util.regex.Pattern;  

/**
 *
 * @author Don
 */
public class Input_regex_checks {
    
    
    public boolean isValidEmailAddress(String emailAddress){  
         String  expression="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name)|(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2,3})|(\\..{2,3}\\..{2,3}))$";  
         CharSequence inputStr = emailAddress;  
         Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);  
         Matcher matcher = pattern.matcher(inputStr);   
         return matcher.matches();  
    }  
    
    public boolean lettersOnly(String letters) {
        return letters.matches("^[a-zA-Z]+$");
    }
    
    public boolean numbersOnly(String numbers){
        return numbers.matches("^[0-9]+$");
    }
    
    public boolean floatOnly (String fnumber){
        return fnumber.matches("^(\\+?((([0-9]+(\\.)?)|([0-9]*\\.[0-9]+))([eE][+-]?[0-9]+)?))$");
    }
    
    public boolean dateOnly(String date){
       SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd");
       try{
           format.parse(date);
           return true;
       }
       catch(Exception e){
           return false;
       }
    }
    
    public boolean lettersNumbersSpace(String synopsis)
    {   
        //return synopsis.matches("(a-zA-Z0-9[ \t])+");
        return synopsis.matches("[a-zA-Z0-9\\.\\?\\ ]+");
    }
    //877
    public boolean lettersNumbers (String letternumber)
    {
        return letternumber.matches("^[0-9a-zA-Z]+$");
    }
}
